<template>
  <div>
    <el-card class="box-msg">
      <div>
        <span class="patient-name">
          {{ this.data.name == undefined ? '未选择病人' : this.data.name }}
        </span>
        <el-button
          type="primary"
          size="small"
          class="input-item"
          @click="feitianmolong"
        >查看院内详情</el-button
        >
      </div>
      <div class="msg1">
        <p class="item">
          床号: {{ this.data.bed_code }}
          <el-button
            type="primary"
            size="small"
            :disabled="noPatient"
            class="input-item"
            @click="bedEditClick"
          >修改
          </el-button
          >
        </p>
        <p class="item">住院号：{{ this.data.visit_id }}</p>
        <p class="item">性别：{{ this.data.sex }}</p>
        <p class="item">年龄：{{ this.data.ageOrMonthAge }}</p>
        <p class="item">入院天数: {{ this.data.department_days == undefined ? '' : this.data.department_days }}</p>
        <p class="item">入院时间: {{ this.data.visit_time }}</p>
        <p class="item">
          入科时间：{{ enterTime }}
          <el-button
            type="primary"
            size="small"
            :disabled="noPatient"
            class="input-item"
            @click="enterTimeVisible = true"
          >修改
          </el-button
          >
        </p>
        <p class="item">出科时间：{{ this.data.exit_time }}</p>
        <p class="item">
          状态：{{ this.flagState }}
          <span v-if="this.flagState == '出科'">
            {{ this.data.exit_type == "" ? "--" : this.data.exit_type }}
          </span>
          <el-button
            type="primary"
            size="small"
            :disabled="noPatient"
            class="input-item"
            @click="dialogVisibleFlag = true"
          >修改
          </el-button>
        </p>
        <p class="item">
          诊断：{{ this.data.diagnosis_name }}
          <el-button
            type="primary"
            size="small"
            :disabled="noPatient"
            class="input-item"
            @click="diagnosisVisible = true"
          >修改
          </el-button
          >
        </p>
      </div>

      <div class="msg2">
        是否计划ICU转入：{{ this.data.unplanned }}
        <el-button
          type="primary"
          size="small"
          :disabled="noPatient"
          class="input-item"
          @click="dialogVisibleICU = true"
        >补全信息
        </el-button>
      </div>

      <div class="msg3">
        <p class="item">
          <span>
            患者打印开始页码设置:
            <el-input
              v-model="pageNumber"
              placeholder="请输入页码号"
              style=" width: 120px;"
            ></el-input>
          </span>

          <el-button
            type="primary"
            size="small"
            :disabled="noPatient"
            class="input-item"
            style="float: right"
            @click="printStartPageSetClick"
          >保存
          </el-button>
        </p>
        <p class="item">
          <el-button
            type="primary"
            size="small"
            :disabled="noPatient"
            class="input-item"
            :loading="loading"
            @click="testMinotor"
          >监护仪测试
          </el-button
          >
          {{ this.testIpMsg }}
        </p>
      </div>
    </el-card>

    <el-card>
      <div slot="header">
        <span style="display: inline-block;margin-right: 10px">生命体征监测</span>
        <el-select
          v-model="vitalSignsItem"
          size="small"
          clearable
          style="width: 150px;margin-left: 15px; "
          placeholder="请选择生命体征项"
          @change="getvitalSignsData"
        >
          <el-option
            v-for="item in vitalSignsOptions"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>

        <el-date-picker
          v-model="vitalSignsDate"
          style="width: 150px;margin-left: 15px; "
          size="small"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change="getvitalSignsData"
        />
      </div>
      <div class="chart-info">
        <div id="vitalSignsEcharts" style="height: 400px" v-if="vitalSignsData.length != 0"></div>
        <div class="no-data" v-if="vitalSignsData.length == 0">
          暂无数据
        </div>
      </div>
    </el-card>

    <el-card>
      <div slot="header">
        <span style="display: inline-block;margin-right: 10px">关键指标范围监测</span>
        <el-select
          v-model="monitoringItem"
          size="small"
          clearable
          style="width: 150px;margin-left: 15px; "
          placeholder="请选择观察项"
          @change="getMonitorScopeData"
        >
          <el-option
            v-for="item in monitoringOptions"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>

        <el-date-picker
          v-model="monitorScopeDate"
          style="width: 150px;margin-left: 15px; "
          size="small"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change="getMonitorScopeData"
        />

        <el-button
          type="primary"
          plain
          size="small"
          style="margin-left: 20px"
          :disabled="noPatient"
          @click="monitorScopeDialogVisible=true"
        >监测范围设置
        </el-button>
      </div>
      <div class="chart-info">
        <div id="monitorScopeEcharts" style="height: 400px" v-if="monitoringData.length != 0"></div>
        <div class="no-data" v-if="monitoringData.length == 0">
          暂无数据
        </div>
      </div>
    </el-card>

    <div class="timeline-box">
      <el-card style="width: 50%">
        <div class="title">流转记录</div>
        <el-timeline reverse v-if="transferInfoList.length != 0">
          <el-timeline-item
            v-for="(item, index) in transferInfoList"
            :key="index"
            :timestamp="item.dataTime">
            {{ item.type + ' ' + item.name }}
          </el-timeline-item>
        </el-timeline>
        <div class="no-data" v-if="transferInfoList.length == 0">
          暂无数据
        </div>
      </el-card>
      <el-card style="width: 50%">
        <div class="title">诊疗时间轴</div>
        <el-timeline reverse v-if="timeLineDataList.length != 0">
          <el-timeline-item
            v-for="(item, index) in timeLineDataList"
            :key="index"
            :timestamp="item.eventDate">
            {{ item.eventCode + ' ' + item.name }}
          </el-timeline-item>
        </el-timeline>
        <div class="no-data" v-if="timeLineDataList.length == 0">
          暂无数据
        </div>
      </el-card>
    </div>

    <el-dialog
      title="修改诊断内容"
      :visible.sync="diagnosisVisible"
      width="30%"
    >
      <span>诊断：</span>
      <el-input
        v-model="diagnosisName"
        placeholder="请输入内容"
        style="text-align: center;width: 80%"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="(diagnosisVisible = false), diagnosisNameSetClick()"
        >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="修改入科时间"
      :visible.sync="enterTimeVisible"
      width="30%"
    >
      <span>入科时间：</span>
      <el-date-picker
        v-model="enterTime"
        format="yyyy-MM-dd HH:mm:ss"
        value-format="yyyy-MM-dd HH:mm:ss"
        type="datetime"
        placeholder="选择日期时间"
      >
      </el-date-picker>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="(enterTimeVisible = false), enterTimeSetClick()"
        >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="补全信息"
      :visible.sync="dialogVisibleICU"
      width="30%"
    >
      <span>是否计划ICU转入：</span>
      <el-select v-model="icuFlag">
        <el-option
          v-for="item in icuList"
          :key="item.id"
          :label="item.name"
          :value="item.name"
        ></el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="(dialogVisibleICU = false), ICUSetClick()"
        >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="状态修改"
      :visible.sync="dialogVisibleFlag"
      width="30%"
    >
      <span>状态：</span>
      <el-select v-model="flagState">
        <el-option
          v-for="item in flagList"
          :key="item.id"
          :label="item.name"
          :value="item.name"
        ></el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="(dialogVisibleFlag = false), flagSetClick()"
        >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="床位修改"
      :visible.sync="bedEditVisible"
      width="30%"
    >
      <span>床位号：</span>
      <el-select v-model="bedCode">
        <el-option
          v-for="item in bedList"
          :key="item.id"
          :label="item.bed_code"
          :value="item.bed_code"
        ></el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="bedSelectedClick"
        >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 监测范围设置 -->
    <el-dialog
      title="监测范围设置"
      :visible.sync="monitorScopeDialogVisible"
      width="30%"
    >
      <el-form label-width="120px">
        <el-form-item label="范围设置项:">
          <el-select
            v-model="monitorScopeDialogInfo.selected"
            size="small"
            placeholder="请选择设置项"
            @change="monitorScopeSetChange"
          >
            <el-option
              v-for="item in monitoringOptions"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="下限:">
          <el-input v-model="monitorScopeDialogInfo.lower"/>
        </el-form-item>
        <el-form-item label="上限:">
          <el-input v-model="monitorScopeDialogInfo.upper"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="monitorScopeDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="monitorScopeSaveClick">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  dibaotianxinggai,
  patientupdateEnterTime,
  updatePatientIcuFlag,
  patientgetUrl,
  testIp,
  insertPage,
  findPage,
  vitalSignsDataQuery,
  timeLineDataQuery,
  transferInfoQuery,
  monitorScopeQuery, monitorScopeUpdate, List, queryIcuBedList, updateExitBed, updateFlag, getUser,
} from "@/api/table";
import {Message} from "element-ui";
import {dateUtils} from "@/utils/dateUtils";
import * as echarts from 'echarts';

export default {
  data() {
    return {
      noPatient: true,
      pageNumber: "",
      endTime: "",
      icuFlag: "",
      flagState: '',
      bedCode: '',
      bedList: [],
      data: {},
      diagnosisName: "",
      enterTime: "",
      testIpMsg: "",
      dialogVisibleFlag: false, //在科状态
      dialogVisibleICU: false,
      diagnosisVisible: false,
      enterTimeVisible: false,
      bedEditVisible: false,
      monitorScopeDialogVisible: false, //生命体征监测范围设置弹窗
      loading: false,
      icuList: [
        {id: "1", name: "是", value: "1"},
        {id: "2", name: "否", value: "2"},
      ],
      flagList: [
        {id: "1", name: "在科", value: "在科"},
        {id: "2", name: "出科", value: "出科"},
      ],
      transferInfoList: [],
      timeLineDataList: [],
      vitalSignsData: [],
      monitoringData: [],
      vitalSignsDate: '',
      monitorScopeDate: '',
      monitorScopeDialogInfo: {
        selected: "", //选中项
        lower: '', //下限
        upper: '', //上限
      },
      vitalSignsItem: "", //生命体征选中项
      vitalSignsOptions: [
        {
          id: 0,
          value: "体温",
          label: "体温",
        }, {
          id: 1,
          value: "心率",
          label: "心率",
        }, {
          id: 2,
          value: "血糖",
          label: "血糖",
        }, {
          id: 3,
          value: "血压",
          label: "血压",
        }
      ],
      monitoringItem: "", //观察选中项
      monitoringOptions: [
        {
          id: 0,
          value: "体温",
          label: "体温",
        }, {
          id: 1,
          value: "心率",
          label: "心率",
        }, {
          id: 2,
          value: "血糖",
          label: "血糖",
        }, {
          id: 3,
          value: "收缩压",
          label: "收缩压",
        }, {
          id: 4,
          value: "舒张压",
          label: "舒张压",
        }],
      monitorScopeList: [],  //监测范围设置列表
      loginName: ""
    };
  },
  computed: {
    getData() {
      return this.$store.state.user.severFall;
    }
  },
  watch: {
    getData() {
      this.initData();
    }
  },
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.data = this.$store.state.user.severFall;

      if (this.data.patient_id == undefined) {
        Message({message: "请选择病人", type: "warning"});
        return;
      }

      this.noPatient = false;
      this.diagnosisName = this.data.diagnosis_name;
      this.enterTime = this.data.enter_time;
      this.icuFlag = this.data.unplanned;
      this.flagState = this.data.flag;
      this.vitalSignsDate = dateUtils(1, new Date());
      this.monitorScopeDate = dateUtils(1, new Date());

      findPage({patientId: this.data.patient_id,}).then((res) => {
        if(res.data.length != 0){
          this.pageNumber = res.data[0].pageNum;
        }
      });

      //获取时间轴信息
      timeLineDataQuery(this.data.patient_id).then((res) => {
        this.timeLineDataList = res.data;
      });
      //获取流转信息
      transferInfoQuery(this.data.patient_id).then((res) => {
        this.transferInfoList = res.data;
      });
      this.feitianmoji();
      this.getMonitorScope();
      this.getMonitorScopeData();
      this.getvitalSignsData();
    },
    //获取监测范围
    getMonitorScope() {
      monitorScopeQuery({patientId: this.data.patient_id,}).then((res) => {
        this.monitorScopeList = res.data;
      });
    },
    //获取监测范围数据
    getMonitorScopeData() {
      vitalSignsDataQuery({
        patientId: this.data.patient_id,
        date: this.monitorScopeDate
      }).then((res) => {
        if (res.code == 200) {
          this.monitoringData = res.data;
          if(this.monitoringData.length != 0){
            this.monitorScopeEchartsInit();
          }
          if (this.monitoringData.length === 0) {
            var chartDom = document.getElementById('monitorScopeEcharts');
            var myChart = echarts.init(chartDom);
            myChart.dispose()
          }
        } else {
          this.monitoringData = [];
        }
      });
    },
    feitianmoji() {
      getUser().then((res) => {
        this.loginName = res.data.workNumber.trim();
      });
    },
    feitianmolong() {
      if (this.loginName === "admin") {
        alert("没有权限查看院内详情");
      } else {
        patientgetUrl({
          userWorkNumber: this.loginName,
          visitId: this.data.visit_id,
        }).then((res) => {
          if (res.code === 200) {
            window.open(res.data);
          } else {
            alert(res.msg);
          }
        });
      }
    },
    //获取生命体征信息
    getvitalSignsData() {
      vitalSignsDataQuery({
        patientId: this.data.patient_id,
        date: this.vitalSignsDate
      }).then((res) => {
        if (res.code == 200) {
          this.vitalSignsData = res.data;
          if(this.monitoringData.length != 0){
            this.vitalSignsEchartsInit();
          }
          if (this.vitalSignsData.length === 0) {
            var chartDom = document.getElementById('vitalSignsEcharts');
            var myChart = echarts.init(chartDom);
            myChart.dispose()
          }
        } else {
          this.vitalSignsData = [];
        }
      });
    },
    // getEchartsData() {
    //   var echartsData = {
    //     time: {
    //       name: '时间',
    //       data: []
    //     },
    //     temperature: {
    //       name: '体温',
    //       data: []
    //     },
    //     bloodGlucose: {
    //       name: '血糖',
    //       data: []
    //     },
    //     hr: {
    //       name: '心率',
    //       data: []
    //     },
    //     sbp: {
    //       name: '收缩压',
    //       data: []
    //     },
    //     dbp: {
    //       name: '舒张压',
    //       data: []
    //     },
    //   }
    //
    //   this.vitalSignsData.forEach(item => {
    //     echartsData.time.data.push(item.dataTime);
    //     echartsData.temperature.data.push(item.template);
    //     echartsData.bloodGlucose.data.push(item.bloodGlucose);
    //     echartsData.hr.data.push(item.hr);
    //     echartsData.sbp.data.push(item.sbp);
    //     echartsData.dbp.data.push(item.dbp);
    //   });
    //
    //   return echartsData;
    // },
    getEchartsData() {
      var echartsData = {
        time: {
          name: '时间',
          data: Array.from({ length: 24 }, (_, i) => i)
        },
        temperature: {
          name: '体温',
          data: Array(24).fill(0)
        },
        bloodGlucose: {
          name: '血糖',
          data: Array(24).fill(0)
        },
        hr: {
          name: '心率',
          data: Array(24).fill(0)
        },
        sbp: {
          name: '收缩压',
          data: Array(24).fill(0)
        },
        dbp: {
          name: '舒张压',
          data: Array(24).fill(0)
        },
      };
      this.vitalSignsData.forEach(item => {
        const timeIndex = parseInt(item.dataTime, 10);
        echartsData.temperature.data[timeIndex] = item.template;
        echartsData.bloodGlucose.data[timeIndex] = item.bloodGlucose;
        echartsData.hr.data[timeIndex] = item.hr;
        echartsData.sbp.data[timeIndex] = item.sbp;
        echartsData.dbp.data[timeIndex] = item.dbp;
      });
      return echartsData;
    },
    //生命体征监测表格
    vitalSignsEchartsInit() {
      var echartsData = this.getEchartsData();
      var dataList;

      switch (this.vitalSignsItem) {
        case '体温':
          dataList = [{
            name: echartsData.temperature.name,
            type: 'line',
            data: echartsData.temperature.data
          }]
          break;
        case '心率':
          dataList = [{
            name: echartsData.hr.name,
            type: 'line',
            data: echartsData.hr.data
          }]
          break;
        case '血糖':
          dataList = [{
            name: echartsData.bloodGlucose.name,
            type: 'line',
            data: echartsData.bloodGlucose.data
          }]
          break;
        case '血压':
          dataList = [{
            name: echartsData.sbp.name,
            type: 'line',
            data: echartsData.sbp.data
          }, {
            name: echartsData.dbp.name,
            type: 'line',
            data: echartsData.dbp.data
          }]
          break;
        default:
          dataList = [{
            name: echartsData.temperature.name,
            type: 'line',
            data: echartsData.temperature.data
          }, {
            name: echartsData.hr.name,
            type: 'line',
            data: echartsData.hr.data
          }, {
            name: echartsData.bloodGlucose.name,
            type: 'line',
            data: echartsData.bloodGlucose.data
          }, {
            name: echartsData.sbp.name,
            type: 'line',
            data: echartsData.sbp.data
          }, {
            name: echartsData.dbp.name,
            type: 'line',
            data: echartsData.dbp.data
          }]
          break;
      }

      var option = {
        title: {
          text: ''
        },
        tooltip: {
          // trigger: 'axis', //数据太多，无法显示
          trigger: 'item',
          axisPointer: {
            show: true,
            type: 'cross',
            lineStyle: {
              type: 'dashed',
              width: 1
            }
          }
        },
        legend: {
          data: [echartsData.temperature.name, echartsData.hr.name, echartsData.bloodGlucose.name,
            echartsData.sbp.name, echartsData.dbp.name]
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: echartsData.time.data
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value} '
          },
        },
        series: dataList
      };

      setTimeout(() => {
        var chartDom = document.getElementById('vitalSignsEcharts');
        var myChart = echarts.init(chartDom);
        myChart.setOption(option, true);
      }, 0);
    },
    getMonitorEchartsData() {
      var echartsData = {
        time: {
          name: '时间',
          data: Array.from({ length: 24 }, (_, i) => i)
        },
        temperature: {
          name: '体温',
          data: Array(24).fill(0)
        },
        bloodGlucose: {
          name: '血糖',
          data: Array(24).fill(0)
        },
        hr: {
          name: '心率',
          data: Array(24).fill(0)
        },
        sbp: {
          name: '收缩压',
          data: Array(24).fill(0)
        },
        dbp: {
          name: '舒张压',
          data: Array(24).fill(0)
        },
      };

      this.vitalSignsData.forEach(item => {
        const timeIndex = parseInt(item.dataTime, 10);
        echartsData.temperature.data[timeIndex] = item.template;
        echartsData.bloodGlucose.data[timeIndex] = item.bloodGlucose;
        echartsData.hr.data[timeIndex] = item.hr;
        echartsData.sbp.data[timeIndex] = item.sbp;
        echartsData.dbp.data[timeIndex] = item.dbp;
      });

      return echartsData;
      // var echartsData = {
      //   time: {
      //     name: '时间',
      //     data: []
      //   },
      //   temperature: {
      //     name: '体温',
      //     data: []
      //   },
      //   bloodGlucose: {
      //     name: '血糖',
      //     data: []
      //   },
      //   hr: {
      //     name: '心率',
      //     data: []
      //   },
      //   sbp: {
      //     name: '收缩压',
      //     data: []
      //   },
      //   dbp: {
      //     name: '舒张压',
      //     data: []
      //   },
      // }
      //
      // this.monitoringData.forEach(item => {
      //   echartsData.time.data.push(item.dataTime);
      //   echartsData.temperature.data.push(item.template);
      //   echartsData.bloodGlucose.data.push(item.bloodGlucose);
      //   echartsData.hr.data.push(item.hr);
      //   echartsData.sbp.data.push(item.sbp);
      //   echartsData.dbp.data.push(item.dbp);
      // });
      //
      // return echartsData;
    },
    //监测范围表格
    monitorScopeEchartsInit() {
      var echartsData = this.getMonitorEchartsData();
      var dataList, markLine;

      switch (this.monitoringItem) {
        case '体温':
          dataList = [{
            name: echartsData.temperature.name,
            type: 'line',
            data: echartsData.temperature.data,
            markLine: this.getMarkLine('体温')
          }]

          break;
        case '心率':
          dataList = [{
            name: echartsData.hr.name,
            type: 'line',
            data: echartsData.hr.data,
            markLine: this.getMarkLine('心率')
          }]
          break;
        case '血糖':
          dataList = [{
            name: echartsData.bloodGlucose.name,
            type: 'line',
            data: echartsData.bloodGlucose.data,
            markLine: this.getMarkLine('血糖')
          }]
          break;
        case '舒张压':
          dataList = [{
            name: echartsData.dbp.name,
            type: 'line',
            data: echartsData.dbp.data,
            markLine: this.getMarkLine('舒张压')
          }]
          break;
        case '收缩压':
          dataList = [{
            name: echartsData.sbp.name,
            type: 'line',
            data: echartsData.sbp.data,
            markLine: this.getMarkLine('收缩压')
          }]
          break;
        default:
          dataList = [
            {
            name: echartsData.temperature.name,
            type: 'line',
            data: echartsData.temperature.data
          }, {
            name: echartsData.hr.name,
            type: 'line',
            data: echartsData.hr.data
          }, {
            name: echartsData.bloodGlucose.name,
            type: 'line',
            data: echartsData.bloodGlucose.data
          }, {
            name: echartsData.sbp.name,
            type: 'line',
            data: echartsData.sbp.data
          }, {
            name: echartsData.dbp.name,
            type: 'line',
            data: echartsData.dbp.data
          }]
          markLine = {}
          break;
      }

      var option = {
        title: {
          text: ''
        },
        tooltip: {
          // trigger: 'axis', //数据太多，无法显示
          trigger: 'item',
          axisPointer: {
            show: true,
            type: 'cross',
            lineStyle: {
              type: 'dashed',
              width: 1
            }
          }
        },
        legend: {
          data: [echartsData.temperature.name, echartsData.hr.name, echartsData.bloodGlucose.name,
            echartsData.sbp.name, echartsData.dbp.name]
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: echartsData.time.data
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value} '
          },
        },
        series: dataList
      };

      setTimeout(() => {
        var chartDom = document.getElementById('monitorScopeEcharts');
        var myChart = echarts.init(chartDom);
        myChart.setOption(option, true);
      }, 0);
    },
    //设置页码
    printStartPageSetClick() {
      if (this.pageNumber == "") {
        Message({
          message: "请填写开始页码",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      if (!/(^[0-9]*[1-9][0-9]*$)/.test(this.pageNumber)) {
        Message({
          message: "请填写正确的开始页码",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      insertPage({
        patientId: this.data.patient_id,
        pageNum: this.pageNumber,
      }).then((res) => {
        if (res.code == 200) {
          findPage({
            patientId: this.data.patient_id,
          }).then((res) => {
            this.pageNumber = res.data[0].pageNum;

            Message({
              message: "操作成功",
              type: "success",
              duration: 1500,
            });
          });
        }
      });
    },
    //监护仪测试
    testMinotor() {
      this.loading = true;
      testIp({
        bedCode: this.data.bed_code,
      }).then((res) => {
        this.testIpMsg = res.msg;
        Message({message: res.msg, type: "info"});
        this.loading = false;
      });
    },
    //诊断信息修改
    diagnosisNameSetClick() {
      dibaotianxinggai({
        id: this.data.patient_id,
        diagnosisName: this.diagnosisName,
      }).then((res) => {
        if (res.code == 200) {
          this.data.diagnosis_name = this.diagnosisName;
          this.$store.dispatch("user/restseverFall", this.data);
        }
        Message({message: res.msg, type: "success"});
      });
    },
    //入科时间修改
    enterTimeSetClick() {
      patientupdateEnterTime({
        id: this.data.patient_id,
        enterTime: this.enterTime,
      }).then((res) => {
        if (res.code == 200) {
          this.data.enter_time = this.enterTime;
          this.$store.dispatch("user/restseverFall", this.data);
        }
        Message({message: res.msg, type: "success"});
      });
    },
    //补全信息
    ICUSetClick() {
      var flag = this.icuFlag == "是" ? 1 : this.icuFlag == "否" ? 2 : 0;
      updatePatientIcuFlag({
        id: this.data.patient_id,
        icuFlag: flag,
      }).then((res) => {
        if (res.code == 200) {
          this.data.unplanned = this.icuFlag;
          this.$store.dispatch("user/restseverFall", this.data);
        }
        Message({message: res.msg, type: "success"});
      });
    },
    //在科状态修改
    flagSetClick() {
      var flag = this.flagState == "在科" ? 1 : 0;
      updateFlag({
        patientId: this.data.patient_id,
        flag: flag,
      }).then((res) => {
        if (res.code == 200) {
          this.data.flag = this.flagState;
          this.$store.dispatch("user/restseverFall", this.data);
        }
        Message({message: res.msg, type: "info"});
      });
    },
    //出科患者床位号修改
    bedEditClick() {
      this.bedEditVisible = true;
      queryIcuBedList({size: 1000, start: 1}).then((res) => {
        this.bedList = res.data;
      });
    },
    bedSelectedClick(){
      updateExitBed({
        patientId: this.data.patient_id,
        bedCode: this.bedCode,
      }).then((res) => {
        if (res.code == 200) {
          this.data.bed_code = this.bedCode;
        }
        Message({message: res.msg, type: "info"});

        this.bedEditVisible = false;
      });
    },
    getMarkLine(itemCode) {
      var item = this.getMonitorScopeItem(itemCode);

      if(item == undefined){
        return {}
      }
      var obj = {
        symbol: ['none', 'none'], //去掉箭头
        lineStyle: {
          normal: {
            type: 'dashed',
            // color: 'red', // 这儿设置安全基线颜色
          },
        },
        data: [{
          yAxis: item.maxValue,
        }, {
          yAxis: item.minValue,
        },
        ]
      }

      return obj;
    },
    getMonitorScopeItem(itemCode) {
      let listItem;
      for (let i = 0; i < this.monitorScopeList.length; i++) {
        if (this.monitorScopeList[i].itemCode == itemCode) {
          listItem = this.monitorScopeList[i];
          break;
        }
      }

      return listItem;
    },
    monitorScopeSetChange(){
      if(this.monitorScopeDialogInfo.selected == ''){
          this.monitorScopeDialogInfo.upper = '';
          this.monitorScopeDialogInfo.lower = '';
          return;
      }

      var item = this.getMonitorScopeItem(this.monitorScopeDialogInfo.selected);
      if(item == undefined){
        this.monitorScopeDialogInfo.upper = '';
        this.monitorScopeDialogInfo.lower = '';
      }else{
        this.monitorScopeDialogInfo.upper = item.maxValue;
        this.monitorScopeDialogInfo.lower = item.minValue;
      }
    },
    monitorScopeSaveClick() {
      if (this.monitorScopeDialogInfo.selected == '') {
        Message({
          message: "观察项不能为空", type: "warning"
        });
        return;
      }
      monitorScopeUpdate({
        patientId: this.data.patient_id,
        itemCode: this.monitorScopeDialogInfo.selected,
        maxValue: this.monitorScopeDialogInfo.upper,
        minValue: this.monitorScopeDialogInfo.lower
      }).then((res) => {
        this.getMonitorScope();
        this.monitorScopeDialogVisible = false;
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.el-card {
  margin: 15px;
}

.timeline-box {
  display: flex;

  .title {
    font-size: 17px;
    font-weight: bolder;
    margin: 0 0 20px 10px;
  }

  .el-timeline {
    height: 400px;
    overflow-y: auto;
  }
}

.chart-info {
  padding-left: 10px;
  font-size: 14px;
}

.box-msg {
  line-height: 32px;

  .patient-name {
    display: inline-block;
    font-size: 24px;
    font-weight: bold;
    margin-right: 10px;
    vertical-align: middle;
  }

  .msg1 {
    display: flex;
    flex-wrap: wrap;

    .input-item {
      float: right;
    }
  }

  .msg2 {
    width: 395px;
    padding-right: 30px;
    margin: 10px 0;

    .input-item {
      float: right;
    }
  }

  .msg3 {
    .item {
      display: inline-block;
    }

    ::v-deep .el-input__inner {
      height: 32px;
    }
  }

  .item {
    width: 395px;
    padding-right: 30px;
    margin: 10px 0;
  }
}

.no-data{
  font-size: 15px;
  font-weight: lighter;
  text-align: center;
}
</style>

